home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 1 / QRZ Ham Radio Callsign Database - December 1993.iso / ucsd / packet / tcpip / amiga / asrc29k.lha / lapbtime.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-08  |  3.0 KB  |  140 lines

  1. #include "global.h"
  2. #include "mbuf.h"
  3. #include "ax25.h"
  4. #include "timer.h"
  5. #include "lapb.h"
  6.  
  7. static void tx_enq __ARGS((struct ax25_cb *axp));
  8.  
  9. int lapbtimertype = 0;        /* default to binary exponential */
  10.  
  11. /* Called whenever timer T1 expires */
  12. void
  13. recover(p)
  14. void *p;
  15. {
  16.     register struct ax25_cb *axp = (struct ax25_cb *)p;
  17.  
  18.     axp->flags.retrans = 1;
  19.     axp->retries++;
  20.  
  21.     switch(lapbtimertype){
  22.         case 2:
  23.             axp->t1.start = ((axp->srt * 2) / MSPTICK);    /* original backoff mode*/
  24.             break;
  25.         case 1:
  26.             if((1L << axp->retries) < Blimit)
  27.                 axp->t1.start += (axp->srt / MSPTICK);    /* linear backoff mode */
  28.             break;
  29.         case 0:
  30.             if((1L << axp->retries) < Blimit)
  31.                 axp->t1.start *= 2;            /* exponential backoff mode */
  32.             break;
  33.     }
  34.  
  35.     switch(axp->state){
  36.     case LAPB_SETUP:
  37.         if(axp->n2 != 0 && axp->retries > axp->n2){
  38.             free_q(&axp->txq);
  39.             axp->reason = LB_TIMEOUT;
  40.             lapbstate(axp,LAPB_DISCONNECTED);
  41.         } else {
  42.             sendctl(axp,LAPB_COMMAND,SABM|PF);
  43.             start_timer(&axp->t1);
  44.         }
  45.         break;
  46.     case LAPB_DISCPENDING:
  47.         if(axp->n2 != 0 && axp->retries > axp->n2){
  48.             axp->reason = LB_TIMEOUT;
  49.             lapbstate(axp,LAPB_DISCONNECTED);
  50.         } else {
  51.             sendctl(axp,LAPB_COMMAND,DISC|PF);
  52.             start_timer(&axp->t1);
  53.         }
  54.         break;
  55.     case LAPB_CONNECTED:
  56.     case LAPB_RECOVERY:
  57.         if(axp->n2 != 0 && axp->retries > axp->n2){
  58.             /* Give up */
  59.             sendctl(axp,LAPB_RESPONSE,DM|PF);
  60.             free_q(&axp->txq);
  61.             axp->reason = LB_TIMEOUT;
  62.             lapbstate(axp,LAPB_DISCONNECTED);
  63.         } else {
  64.             /* Transmit poll */
  65.             tx_enq(axp);
  66.             lapbstate(axp,LAPB_RECOVERY);
  67.         }
  68.         break;
  69.     }
  70. }
  71.  
  72. /* Send a poll (S-frame command with the poll bit set) */
  73. void
  74. pollthem(p)
  75. void *p;
  76. {
  77.     register struct ax25_cb *axp;
  78.  
  79.     axp = (struct ax25_cb *)p;
  80.     if(axp->proto == V1)
  81.         return;    /* Not supported in the old protocol */
  82.     switch(axp->state){
  83.     case LAPB_CONNECTED:
  84.         axp->retries = 0;
  85.         tx_enq(axp);
  86.         lapbstate(axp,LAPB_RECOVERY);
  87.         break;
  88.     }
  89. }
  90.  
  91. /* Called whenever timer T4 (link rudundancy timer) expires */
  92. void
  93. redundant(p)
  94. void *p;
  95. {
  96.     register struct ax25_cb *axp;
  97.  
  98.     axp = (struct ax25_cb *)p;
  99.     switch(axp->state){
  100.     case LAPB_CONNECTED:
  101.     case LAPB_RECOVERY:
  102.         axp->retries = 0;
  103.         sendctl(axp,LAPB_COMMAND,DISC|PF);
  104.         start_timer(&axp->t1);
  105.         free_q(&axp->txq);
  106.         lapbstate(axp,LAPB_DISCPENDING);
  107.         break;
  108.     }
  109. }
  110.  
  111. /* Transmit query */
  112. static void
  113. tx_enq(axp)
  114. register struct ax25_cb *axp;
  115. {
  116.     char ctl;
  117.     struct mbuf *bp;
  118.  
  119.     /* I believe that retransmitting the oldest unacked
  120.      * I-frame tends to give better performance than polling,
  121.      * as long as the frame isn't too "large", because
  122.      * chances are that the I frame got lost anyway.
  123.      * This is an option in LAPB, but not in the official AX.25.
  124.      */
  125.     if(axp->txq != NULLBUF
  126.      && (len_p(axp->txq) < axp->pthresh || axp->proto == V1)){
  127.         /* Retransmit oldest unacked I-frame */
  128.         dup_p(&bp,axp->txq,0,len_p(axp->txq));
  129.         ctl = PF | I | ((axp->vs - axp->unack) & MMASK) << 1
  130.          | axp->vr << 5;
  131.         sendframe(axp,LAPB_COMMAND,ctl,bp);
  132.     } else {
  133.         ctl = len_p(axp->rxq) >= axp->window ? RNR|PF : RR|PF;    
  134.         sendctl(axp,LAPB_COMMAND,ctl);
  135.     }
  136.     axp->response = 0;    
  137.     stop_timer(&axp->t3);
  138.     start_timer(&axp->t1);
  139. }
  140.